module executor.friend.client.ApplyContactExecutor;

import msgtrans;
import message.Constants;
import cache.UserStatusManager;
import hunt.logging;
import google.protobuf;
import message.MsgDefine;
import cache.ChatIdMap;
import client.GateServerClient;
import std.array;
import std.conv : to;
import client.LogicServerClient;

@TransportClient(LogicClientName)
class ApplyContactExecutor : AbstractExecutor!(ApplyContactExecutor){

    @MessageId(MESSAGE.CMD_APPLY_FRIEND_REQ)
    void applyFriend(TransportContext ctx, MessageBuffer buffer)
    {
        ApplyContact applyFriend = new ApplyContact;
        buffer.data.fromProtobuf!ApplyContact(applyFriend);

        if (UserStatusManager.getInstance().getUserStatus(applyFriend.toId)) //online
        {
            TransportSession[ulong] contexts = GateServerClient.getInstance.getAllClient();
            foreach(TransportSession c ; contexts)
            {
                c.send(new MessageBuffer(MESSAGE.CMD_APPLY_FRIEND_REQ,applyFriend.toProtobuf.array));
            }
        } else {
            // 调用 LogicServer 去推送，提醒用户有人加好友
            
        }
    }
}

